
<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>
        X-admin v1.0
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="stylesheet" href="../../static/css/x-admin.css" media="all">
    <link rel="stylesheet" href="../../static/css/dj-css.css" media="all">


</head>

<body>
<div class="x-body">
    <div id="addNews" class="addNews">
        <fieldset class="layui-elem-field layui-field-title" style="margin: 10px -20px 20px;">
            <legend>用户</legend>
        </fieldset>
    <form class="layui-form layui-form-pane" method="post" action="" >
        <div class="layui-form-item">
            <label for="user_name" class="layui-form-label">
                用户名称
            </label>
            <div class="layui-input-inline">
                <input type="text" id="user_name" name="user_name" v-model="user_name" placeholder="请输入用户名称" required="" autocomplete="off" class="layui-input" value="">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="id_card" class="layui-form-label">
                身份证号
            </label>
            <div class="layui-input-inline">
                <input type="text" id="id_card" name="id_card" v-model="id_card"  required=""
                       autocomplete="off" class="layui-input"placeholder="请输入身份证号" lay-verify="idCardNum" value="">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="phone" class="layui-form-label">
                移动电话
            </label>
            <div class="layui-input-inline">
                <input type="text" id="phone" name="phone" v-model="phone"  required="" autocomplete="off" class="layui-input" placeholder="移动电话" value="" lay-verify="phone">
            </div>

        </div>
        <div class="layui-form-item">
            <label for="birthday" class="layui-form-label">
                出生日期
            </label>
            <div class="layui-input-inline">
                <input type="text" name="birthday" id="birthday" lay-verify="date" placeholder="yyyy-mm-dd" autocomplete="off" class="layui-input" v-model="birthday" onclick="layui.laydate({elem: this})">
            </div>
        </div>

        <div class="layui-form-item">

            <div class="dj-select dj-select-inline boxStyle">
                <label   style="height:auto;padding:3px 15px;width:110px;">性别</label>
                <div class="dj-select-content" style="width: 180px;">
                    <div class="dj-select-input" flag = 'true' style="width: 173px;">
                        <span class="dj-selected readOnly" type="text" name=""  selectedCode='' style="line-height:40px;height:40px;width: 173px;" id="sex">请选择性别</span>
                        <i></i>
                    </div>
                    <ul class="dj-select-list" style="width: 173px;">
                        <li code="">请选择性别</li>
                        <li v-for="item in newsTypeList" :code="item.code" >{{item.name}}</li>
                    </ul>
                </div>
            </div>

        </div>

        <div class="layui-form-item">
            <label for="patient_number" class="layui-form-label">
                病案号
            </label>
            <div class="layui-input-inline">
                <input type="text" id="patient_number" name="patient_number" placeholder="请输入病案号" v-model="patient_number"   required="" autocomplete="off" class="layui-input" lay-verify="patient_number">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit lay-filter="add">提交</button>
            </div>
        </div>
    </form>

    </div>
</div>
<script src="../../static/lib/jquery.min.js"></script>
<script src="../../static/lib/vue.min.js"></script>
<script src="../../static/lib/layui/layui.js" charset="utf-8"></script>
<script src="../../static/lib/x-layui.js" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8" src="../../static/lib/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="../../static/lib/ueditor/ueditor.all.min.js"> </script>
<script type="text/javascript" charset="utf-8" src="../../static/lib/ueditor/lang/zh-cn/zh-cn.js"></script>
<script src="../../static/lib/dj-js.js"></script>
<script>


    var VM = new Vue({
        el:"#addNews",
        data:{
            id:'',
            id_card:'',
            phone:'',
            user_name:'',
            sex:'',
            birthday:'',
            patient_number:'',
            newsLists:[],
            newsTypes:[],
            msg:'成功',
            newsTypeList:[]
        },
        created:function(){
//            this.getNews();
            this.getNewsTypeList();
        },
        watch:{
        },
        methods:{
            getNewsTypeList:function(){
                var _this = this;
                $.ajax({
                    url:"../../dictionaries/getDic.do?type=sex",
                    dataType:"json",
                    type:"POST",
                    async:false,
                    success:function (res) {
                        _this.newsTypeList  = res;
                    }
                })
            },
        }
    });

    layui.use(['form','layer','upload','laydate'], function(){
        $ = layui.jquery;
        var form = layui.form(),layer = layui.layer,laydate = layui.laydate;
        //自定义验证规则
        form.verify({
            idCardNum: [/^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/,"请输入正确的18位身份证号！"],
            phone: [/^1[34578]\d{9}$/, '请输入正确的手机号！'],
            patient_number:[/^\+?[1-9][0-9]*$/,"请输入非0正整数作为病案号！"]
        });

        //监听提交
        form.on('submit(add)', function(data){
            var newsType11 = $("#sex").attr("selectedCode");
            $.ajax({
                url:"../../qsuser/save.do",
                dataType:"json",
                data:{
                    idCard:$("#id_card").val(),
                    phoneNumber:$("#phone").val(),
                    userName:$("#user_name").val(),
                    birthday:$("#birthday").val(),
                    sex:newsType11,
                    patientNumber:$("#patient_number").val(),
                },
                type:"POST",
                async:false,
                success:function (res) {
                    if(res.msg=="success"){
                        // 获得frame索引
                        var index = parent.layer.getFrameIndex(window.name);
                        //关闭当前frame
                        parent.location.reload();
                        parent.layer.close(index);
                    }else{
                        layer.msg("增加失败", {icon: 1});
                    }
                },
                error:function (XMLHttpRequest) {
                    layer.msg("系统错误", {icon: 1});
                }
            })
            return false;
        });


    });
</script>
</body>

</html>
